import json
from RedisUtil import *
import time

class Dispatch:
    def __init__(self):
        self.redis = RedisUtil()

    def run(self,data):
        print("====这里是分发====")
        objdata = json.loads(data)
        if objdata["event"] == "heart":
            host = objdata["data"]["host"]
            self.redis.set("servers",str(host),str(int(time.time())))
            print(objdata)
        else:
            print(objdata)
            host = objdata["data"]["host"]
            print(host)
            print(objdata["data"])
            self.redis.appendArray(host,objdata["data"],20)
            print(self.redis.getArray(host))